package hot.linklist;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class A160 {
  class ListNode { int val;
 ListNode next;
 ListNode(int x) {
         val = x;
         next = null;
     }
 }
 ListNode getIntersectionNode(ListNode headA, ListNode headB) {
     Set<ListNode> set=new HashSet<>();
     ListNode n1=headA;
     while(n1!=null){
         set.add(n1);
         n1=n1.next;
     }
     n1=headB;
     while(n1!=null){
         if(set.contains(n1)){
             return n1;
         }
         n1=n1.next;
     }
     return null;
    }
}
